using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace CollegeShop.Infrastructure.Entities.Repository
{
    [Table("T_Putindetail")]
    public class T_Putindetail : IEntity<T_Putindetail>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }

        public int PutInID { get; set; }

        public int PruchaseDetailID { get; set; }

        public int GoodsId { get; set; }

        public int PutInAmount { get; set; }

        public int PackStandard { get; set; }

        public decimal PutInPrice { get; set; }

        public decimal PutInMoney { get; set; }

        public decimal SalePrice { get; set; }

        public override T_Putindetail Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.ID == id);
        }

        public override T_Putindetail Find(System.Linq.Expressions.Expression<Func<T_Putindetail, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Putindetail.FirstOrDefault(where);
                if (item != null)
                {
                    this.ID = item.ID;
                    this.PutInID = item.PutInID;
                    this.PruchaseDetailID = item.PruchaseDetailID;
                    this.GoodsId = item.GoodsId;
                    this.PutInAmount = item.PutInAmount;
                    this.PackStandard = item.PackStandard;
                    this.PutInPrice = item.PutInPrice;
                    this.PutInMoney = item.PutInMoney;
                    this.SalePrice = item.SalePrice;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_Putindetail, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Putindetail.Any(where);
            }
        }
    }
}
